import request from '@/utils/request'
import type { UserResponseData, User, AllRoleResponseData, RoleData, SetRoleData } from './type'

enum API {
    ALLUSER_URL = '/admin/acl/user/',
    ADDUSER_URL = '/admin/acl/user/save',
    UPDATEUSER_URL = '/admin/acl/user/update',
    ADDROLE_URL = '/admin/acl/role/save',
    UPDATE_URL = '/admin/acl/role/update',
    USERROLE_URL = '/admin/acl/user/toAssign/',
    SETUSERROLE_URL = '/admin/acl/user/doAssignRole',
    DELETEUSER_URL = '/admin/acl/user/remove/',
    DELETEUSERLIST_URL = '/admin/acl/user/batchRemove'
}

export const reqAllUser = (page: number, limit: number, username: string) => {
    return request.get<any, UserResponseData>(API.ALLUSER_URL + `${page}/${limit}/?username=${username}`)
}

export const reqAddOrUpdateUser = (data: User) => {
    if (data.id) {
        return request.put<any, any>(API.UPDATEUSER_URL, data)
    } else {
        return request.post<any, any>(API.ADDUSER_URL, data)
    }
}

export const reqAllRole = (userId: number | string) => {
    console.log(userId)
    return request.get<any, AllRoleResponseData>(API.USERROLE_URL + userId)
}

export const reqSetUserRole = (data: SetRoleData) => {
    return request.post<any, any>(API.SETUSERROLE_URL, data)
}

export const reqRemoveUser = (userId: number) => {
    return request.delete<any, any>(API.DELETEUSER_URL + userId)
}

export const reqRemoveUserList = (idList: number[]) => {
    return request.delete<any, any>(API.DELETEUSERLIST_URL, { data: idList })
}

export const reqAddRole = (data: any) => {
    console.log(data)
}

export const reqAddOrUpdateUserRole = (data: any) => {
    console.log(data)
}